package com.example.bms.controller;
import com.example.bms.entity.ApiResult;
import com.example.bms.entity.JudgeQuestion;
import com.example.bms.serviceimpl.JudgeQuestionServiceImpl;
import com.example.bms.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @apiNote 用于对判断题的增加和查询
 * @author
 * @email 1605009600@qq.com
 * @since 1.0.0
 */
@RestController
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST,RequestMethod.PUT,RequestMethod.DELETE})
public class JudgeQuestionController {

    @Autowired
    private JudgeQuestionServiceImpl judgeQuestionService;


    /**
     * @apiNote 增加和查询判断题试题
     * @param judgeQuestion 判断题题库的实体类
     * @author
     * @email 1605009600@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @PostMapping("/judgeQuestion")
    public ApiResult add(@RequestBody JudgeQuestion judgeQuestion) {
        int res = judgeQuestionService.add(judgeQuestion);
        if (res != 0) {
            return ApiResultHandler.buildApiResult(200,"添加成功",res);
        }
        return ApiResultHandler.buildApiResult(400,"添加失败",res);
    }


    /**
     * @apiNote 查询最后一条questionId
     * @author
     * @email 1605009600@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @GetMapping("/judgeQuestionId")
    public ApiResult findOnlyQuestionId() {
        JudgeQuestion res = judgeQuestionService.findOnlyQuestionId();
        return  ApiResultHandler.buildApiResult(200,"查询成功",res);
    }
}
